import { UserEntity } from '@/src/user/entities/user.entity'
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn } from 'typeorm'

@Entity('wallet_log')
export class WalletLogEntity {
  @PrimaryGeneratedColumn()
  id: number

  @Column()
  user_id: number

  @ManyToOne(() => UserEntity)
  @JoinColumn({ name: 'user_id' })
  user?: UserEntity

  @Column({ type: 'tinyint', default: 0, comment: '交易类型：1新用户注册 2签到 3订单评价 5点餐 6订单退款' })
  type: number

  @Column({
    type: 'decimal', precision: 10, scale: 2, transformer: {
      to: (value: number) => value,
      from: (value: string) => Number.parseFloat(value),
    }
  })
  fee: number

  @Column({ default: Math.floor(Date.now() / 1000) })
  create_time: number
}